package main

import (
	"context"
	"encoding/json"
	"google.golang.org/grpc"
	"google.golang.org/grpc/metadata"
	"kop/pb"
	"log"
	"time"
)

func main() {

	conn, err := grpc.Dial("127.0.0.1:8888", grpc.WithInsecure())
	if err != nil {
		panic(err)
	}
	defer conn.Close()

	ctx, cancel := ctx("93ea0963f0aeb22bc9eacf6c08d70af9")
	defer cancel()

	c := pb.NewAPIRingServiceClient(conn)
	resp, err := c.AddRing(ctx, &wrappers.Int32Value{Value: 3021})
	if err != nil {
		panic(err)
	}

	b, _ := json.Marshal(resp)
	log.Println(string(b))

}

func ctx(token string) (context.Context, context.CancelFunc) {
	ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
	ctx = metadata.NewOutgoingContext(ctx, metadata.New(map[string]string{"token": token}))
	return ctx, cancel
}
